package system.security.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import system.security.dao.AuthorityTypeDao;
import system.security.entity.AuthorityType;
import system.security.service.AuthorityTypeService;
import system.security.service.ResourceService;


@Service("authorityTypeService")
public class AuthorityTypeServiceImpl implements AuthorityTypeService {

	@Autowired
	AuthorityTypeDao authorityTypeDao;
	
	@Transactional(readOnly=true)
	@Override
	public AuthorityType getById(int authorityTypeId) {
		AuthorityType authorityType = authorityTypeDao.get(authorityTypeId);
		return authorityType;
	}

	@Override
	public AuthorityType findByName(String authorityTypename) {
			List<AuthorityType> list = authorityTypeDao.findByProperty("authorityTypename", authorityTypename);
			if(!list.isEmpty()){
				return list.get(0);
			}
			return null;		
	}

	@Override
	@Transactional(readOnly = true)
	public List<AuthorityType> getAll() {
		return authorityTypeDao.list();
	}
	
	@Override
	public void save(AuthorityType authorityType) throws Exception {
			authorityTypeDao.saveOrUpdate(authorityType);
	}

	@Override
	public void delete(int authorityTypeId) {
		authorityTypeDao.remove(authorityTypeId);
	}
	
	@Override
	public void delete(AuthorityType authorityType){
		authorityTypeDao.remove(authorityType);		
	}

	
}
